package com.ruoyi.project.system.cat.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.cat.domain.Cat;
import com.ruoyi.project.system.cat.service.ICatService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 装修风格Controller
 * 
 * @author Leil
 * @date 2020-03-07
 */
@Controller
@RequestMapping("/system/cat")
public class CatController extends BaseController
{
    private String prefix = "system/cat";

    @Autowired
    private ICatService catService;

    @RequiresPermissions("system:cat:view")
    @GetMapping()
    public String cat()
    {
        return prefix + "/cat";
    }

    /**
     * 查询装修风格列表
     */
    @RequiresPermissions("system:cat:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Cat cat)
    {
        startPage();
        List<Cat> list = catService.selectCatList(cat);
        return getDataTable(list);
    }

    /**
     * 导出装修风格列表
     */
    @RequiresPermissions("system:cat:export")
    @Log(title = "装修风格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cat cat)
    {
        List<Cat> list = catService.selectCatList(cat);
        ExcelUtil<Cat> util = new ExcelUtil<Cat>(Cat.class);
        return util.exportExcel(list, "cat");
    }

    /**
     * 新增装修风格
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存装修风格
     */
    @RequiresPermissions("system:cat:add")
    @Log(title = "装修风格", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Cat cat)
    {
        return toAjax(catService.insertCat(cat));
    }

    /**
     * 修改装修风格
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Cat cat = catService.selectCatById(id);
        mmap.put("cat", cat);
        return prefix + "/edit";
    }

    /**
     * 修改保存装修风格
     */
    @RequiresPermissions("system:cat:edit")
    @Log(title = "装修风格", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Cat cat)
    {
        return toAjax(catService.updateCat(cat));
    }

    /**
     * 删除装修风格
     */
    @RequiresPermissions("system:cat:remove")
    @Log(title = "装修风格", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(catService.deleteCatByIds(ids));
    }
}
